package com.jianbo.proxy.core;

import org.smartboot.http.server.HttpRequest;

import com.jianbo.proxy.api.Api;
import com.jianbo.proxy.api.ApiFactory;
import com.jianbo.proxy.conf.PropertiesConf;
import com.jianbo.proxy.entity.HttpResponseMiddle;
import com.jianbo.proxy.util.Debug;

/**
 * smart-http-proxy 中预设的接口
 */
public class PresetApiWeb implements Web {

    @Override
    public boolean handle(String path, HttpRequest request, HttpResponseMiddle response) throws Exception {
        boolean openPresetApi = PropertiesConf.getInstance().isPresetApi();
        if(openPresetApi == false) {
            return false;
        }
        Debug.info("PresetApiWeb handle", path);
        Api api = ApiFactory.get(path);
        if(api == null) {
            return false;
        }
        api.execute(request, response);
        return true;
    }
    
}
